package com.example.test.controller;


import com.example.test.bean.DTO.input.GoodsCreateInputDTO;
import com.example.test.bean.DTO.input.GoodsUpdateInputDTO;
import com.example.test.common.model.PageModel;
import com.example.test.common.model.R;
import com.example.test.service.GoodsService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品信息表 前端控制器
 * </p>
 *
 * @author dz
 * @since 2022-04-10
 */
@CrossOrigin
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @ApiOperation(value = "商品信息表根据keyword分页查询")
    @GetMapping("/getGoods")
    public R pageList( String keyword, PageModel pageModel) {
        return goodsService.getGoodsByKeyword(keyword,pageModel);
    }

    @ApiOperation(value = "商品信息表分页查询")
    @GetMapping("/getAllGoods")
    public R getAllGoods(PageModel pageModel) {
        return goodsService.getAllGoods(pageModel);
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/insert")
    public R insert(@Validated @ApiParam  GoodsCreateInputDTO goodsCreateInputDTO) {
        return goodsService.addGoods(goodsCreateInputDTO);
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public R update(@Validated @ApiParam GoodsUpdateInputDTO goodsUpdateInputDTO) {
        return goodsService.updateGoods(goodsUpdateInputDTO);
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@Validated @ApiParam Long goodsId) {
        return goodsService.deleteGoods(goodsId);
    }

}

